﻿using System.Windows.Controls;
using System.Windows.Interactivity;

namespace wpf.Triage.Behavior
{
    public class DataGridRowHeaderBehavior : Behavior<DataGrid>
    {
        /// <summary>
        /// DataGrid附加事件  2022-03-28
        /// </summary>
        protected override void OnAttached()
        {
            AssociatedObject.LoadingRow += AssociatedObject_LoadingRow;
        }
        /// <summary>
        /// 行加载事件  2022-03-28
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AssociatedObject_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }
        /// <summary>
        /// 行为拆除事件  2022-03-28
        /// </summary>
        protected override void OnDetaching()
        {
            AssociatedObject.LoadingRow -= AssociatedObject_LoadingRow;
        }
    }
}
